package com.cdut.logistics.model.dao.datacentre;

import java.util.Date;

import com.cdut.logistics.model.entity.datacentre.BaseDept;
import com.jfinal.plugin.activerecord.Db;

/**  
 * @ClassName: DeptDao  
 * @Description: 操作数据库
 * @author wxt.xia
 * @date 2018年1月26日 下午4:28:22    
 */
public class Dept extends BaseDept<Dept> {
	private static final long serialVersionUID = 1L;
	public String baseSql = " and is_use = 1";
	public String sql1 = "SELECT "+
			"department.id, "+
			"school.`name` as 'school_name', "+
			"department.school_id, "+
			"department.`name`, "+
			"department.is_use "+
			"FROM department  join school "+
			"ON department.school_id=school.id "+
			"AND department.name like ?"+
			"AND department.is_use = 1 "+
			"AND school.is_use = 1";
	public String sql2 = "UPDATE department set name =?, updated=? where id =?"+ baseSql;
	public String sql3 = "UPDATE department set is_use =?, updated=? where id =?"+ baseSql;
	/**  
	 * @Title: save  
	 * @Description: 新增部门
	 * @author wxt.xia
	 * @param dept
	 * @throws  
	 */
	public void save(Dept dept) {
		dept.set("created", new Date());
		dept.set("updated", new Date());
		dept.set("is_use", 1);
		dept.set("active", 1);
		dept.save();
	}

	/**  
	 * @Title: update  
	 * @Description: 修改部门
	 * @author wxt.xia
	 * @param dept
	 * @throws  
	 */
	public void update(Dept dept) {
		dept.set("updated", new Date());
		Db.update(sql2,dept.getName(),dept.getUpdated(),dept.getId());
	}

	/**  
	 * @Title: remove  
	 * @Description: 删除部门
	 * @author wxt.xia
	 * @param id
	 * @throws  
	 */
	public void remove(int id) {
		Db.update(sql3,0,new Date(),id);
	}
}
